package com.example.zqh.controller;


import com.example.zqh.model.RespBean;
import com.example.zqh.pojo.Shop;
import com.example.zqh.pojo.params.OneStringOneNumber;
import com.example.zqh.pojo.params.FourString;
import com.example.zqh.pojo.params.TwoInt;
import com.example.zqh.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-09-10
 */
@RestController
@RequestMapping("/shop")
@Api(tags = "商店表的增删改查")
public class ShopController {

    @Autowired
    ShopService shopService;


    /**
      * @Author: zqh
      * @Date:
      * @Description: 添加一个新商店
    */
    @ApiOperation(value = "添加一个新商店")
    @PostMapping("addANewStore")
    public RespBean addANewStore(@RequestBody FourString threeString, Principal principal){
        return shopService.addANewStore(threeString,principal);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改店铺名
    */
    @ApiOperation(value = "修改店铺名")
    @PostMapping("modifyTheStoreName")
    public RespBean modifyTheStoreName(@RequestBody OneStringOneNumber oneStringOneNumber){
        return shopService.modifyTheStoreName(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改店铺所在位置
    */
    @ApiOperation(value = "修改店铺所在位置")
    @PostMapping("modifyStoreLocation")
    public RespBean modifyStoreLocation(@RequestBody OneStringOneNumber oneStringOneNumber){
        return shopService.modifyStoreLocation(oneStringOneNumber);
    }
    
    /**
      * @Author: zqh
      * @Date: 
      * @Description: 修改店铺简介
    */
    @ApiOperation(value = "修改店铺简介")
    @PostMapping("modifyTheStoreProfile")
    public RespBean modifyTheStoreProfile(@RequestBody OneStringOneNumber oneStringOneNumber){
        return shopService.modifyTheStoreProfile(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改店铺星级，管理员接口
    */
    @ApiOperation(value = "修改店铺星级，管理员接口")
    @PostMapping("modifyStoreStarRating")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean modifyStoreStarRating(@RequestBody TwoInt twoInt){
        return shopService.modifyStoreStarRating(twoInt);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 店铺删除接口，需要管理员权限
    */
    @ApiOperation(value = "店铺删除接口（需要管理员权限）")
    @DeleteMapping("storeDeleteInterface")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean storeDeleteInterface(Integer id){
        return shopService.storeDeleteInterface(id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改店铺图片
    */
    @ApiOperation(value = "修改店铺图片")
    @PostMapping("modifyTheStoreImage")
    public RespBean modifyTheStoreImage(@RequestBody OneStringOneNumber oneStringOneNumber){
        return shopService.modifyTheStoreImage(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 获取所有店铺的数量，放行
    */
    @ApiOperation(value = "获取所有店铺的数量，放行")
    @GetMapping("getAllSp")
    public RespBean getAllSp(){
        return shopService.getAllSp();
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 分页查询店铺
    */
    @ApiOperation(value = "分页查询店铺（放行）")
    @GetMapping("pagingQueryStore")
    public RespBean pagingQueryStore(Integer page,Integer size){
        return shopService.pagingQueryStore(page,size);
    }


    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过店铺id查询店铺
    */
    @ApiOperation(value = "通过店铺id查询店铺(放行)")
    @GetMapping("searchStoreByStoreId")
    public RespBean searchStoreByStoreId(Integer id){
        return shopService.searchStoreByStoreId(id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过星级查询店铺，分页
    */
    @ApiOperation(value = "通过星级查询店铺，分页（放行）")
    @GetMapping("searchStoresByStarRating")
    public RespBean searchStoresByStarRating(Integer start,Integer page,Integer size){
        return shopService.searchStoresByStarRating(start,page,size);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过星级查询不同商店的数量
    */
    @ApiOperation(value = "通过星级查询不同商店的数量（放行）")
    @GetMapping("getNumberByStart")
    public RespBean getNumberByStart(Integer start){
        return shopService.getNumberByStart(start);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 管理员修改商店信息接口
    */
    @ApiOperation(value = "管理员修改商店信息接口")
    @PostMapping("adminModifyStoreInformationInterface")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean adminModifyStoreInformationInterface(@RequestBody Shop shop){
        return shopService.adminModifyStoreInformationInterface(shop);
    }




}

